package LeetCode;

import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}23:46
 */
public class LeetCode213 {
    public int rob(int[] nums) {
        if (nums.length == 0){
            return 0;
        }else if (nums.length == 1){
            return nums[0];
        }
        return Math.max(MyRob(Arrays.copyOfRange(nums,0,nums.length - 1)),
                MyRob(Arrays.copyOfRange(nums,1,nums.length)));
    }

    public int MyRob(int[] nums){
        int pre = 0;
        int cur = 0;
        for (int i = 0; i < nums.length; i++){
            int temp = cur;
            cur = Math.max(cur,pre + nums[i]);
            pre = temp;
        }
        return cur;
    }

}
